package snowflake

import (
	sf "github.com/bwmarrin/snowflake"
	"time"
)

var node *sf.Node

func Init() (err error) {
	var st time.Time
	st, err = time.Parse("2006-01-02", "2022-07-14") //时间戳
	if err != nil {
		return
	}
	sf.Epoch = st.UnixNano() / 1000000
	var machineID int64 = 1 //机器ID
	node, err = sf.NewNode(machineID)
	return
}

func GenIDInt() int64 {
	_ = Init()
	return node.Generate().Int64()
}

func GenIDString() string {
	_ = Init()
	id := node.Generate()
	return id.String()
}
